﻿#ifndef _RTMP_MESSAGE_H
#define _RTMP_MESSAGE_H

#include <qglobal.h>
#include <QByteArray>

struct RtmpMessageHeader
{
    uint8_t timestamp[3];
    uint8_t length[3];
    uint8_t type_id;
    uint8_t stream_id[4]; /* 小端格式 */
};

struct RtmpMessage
{
    uint32_t timestamp = 0;
    uint32_t length = 0;
    uint8_t  type_id = 0;
    uint32_t stream_id = 0;
    uint32_t extend_timestamp = 0;

    uint64_t _timestamp = 0;
    uint8_t  codecId = 0;

    uint8_t  csid = 0;
    uint32_t index = 0;
    QByteArray payload;

    void Clear()
    {
        index = 0;
        timestamp = 0;
        extend_timestamp = 0;
        if (length > 0) {
            payload.resize(length);
        }
    }

    bool IsCompleted() const
    {
        if (index == length && length > 0 &&
            !payload.isEmpty()) {
            return true;
        }

        return false;
    }
};

#endif // RTMPMESSAGE_H
